/**
 * Copyright (C) 2013-2014 the original author or authors.
 */
package com.foreveross.bsl.system.web;

import java.util.List;
import java.util.Map;

import com.foreveross.bsl.common.utils.mapper.BeanMapper;
import com.foreveross.bsl.system.application.vo.CloudFunctionVo;
import com.google.common.collect.Lists;

/**
 * xxx
 *
 * @author Wangyi
 * @version v1.0
 *
 * @date 2013-8-26
 *
 */
public class LinkedCloudFunction extends CloudFunctionVo {
	
	private int appCount;

	/**
	 * @return the appCount
	 */
	public int getAppCount() {
		return appCount;
	}

	/**
	 * @param appCount the appCount to set
	 */
	public void setAppCount(int appCount) {
		this.appCount = appCount;
	}
	
	public static List<LinkedCloudFunction> buildWithCloudCounts(List<CloudFunctionVo> origins, Map<String, Integer> counts){
		List<LinkedCloudFunction> clouds=Lists.newArrayListWithExpectedSize(origins.size());
		for(CloudFunctionVo c : origins){
			if(c==null){
				continue;
			}
			LinkedCloudFunction lcf=BeanMapper.map(c, LinkedCloudFunction.class);
			if(lcf==null){
				continue;
			}
			if(counts!=null && !counts.isEmpty()){
				Integer n=counts.get(lcf.getId());	
				lcf.setAppCount(n==null ? 0 : n);
			}
			else{
				lcf.setAppCount(0);
			}
			clouds.add(lcf);
		}
		return clouds;
	}
}
